package com.yunhe.day322.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yunhe.day322.dao.OrderDao;
import com.yunhe.day322.domain.Orders;
import com.yunhe.day322.domain.Product;
import com.yunhe.day322.service.OrderService;
import com.yunhe.day322.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderDao orderDao;
    @Override
    public Map<String, Object> findAll(int page,int size) {
        PageHelper.startPage(page,size);
        List<Orders> all = orderDao.findAll();
        Map<String, Object> map = new HashMap<>();
        map.put("list",all);

        PageInfo pageInfo = new PageInfo(all);
        int pageNum = pageInfo.getPageNum();
        int pages = pageInfo.getPages();
        long total = pageInfo.getTotal();

        int size1 = pageInfo.getPageSize();
        boolean isFirstPage = pageInfo.isIsFirstPage();
        boolean isLastPage = pageInfo.isIsLastPage();
        map.put("pageNum",pageNum);
        map.put("pages",pages);
        map.put("total",total);
        map.put("pageSize",size1);
        map.put("isIsFirstPage",isFirstPage);
        map.put("isIsLastPage",isLastPage);
        for (Orders orders : all) {
            System.out.println(orders);

        }
        return map;
    }

    @Override
    public Orders findById(String id) {
        Orders byId = orderDao.findById(id);
        return byId;
    }

    @Override
    public Orders findOrderById(String id) {
        Orders order = orderDao.findById(id);
        return order;
    }

    @Override
    public void save(Orders orders) {

        orderDao.save(orders);
    }

    @Override
    public String findByOrderNum(String orderNum) {
        String byOrderNum = orderDao.findByOrderNum(orderNum);
        return byOrderNum;

    }
    /**
     * 根据id删除订单
     * @param id
     */
    @Override
    public void deleteOrdersById(String id) {
        orderDao.deleteOrdersById(id);
    }

    @Override
    public void edit(Orders orders) {
        System.out.println(orders);
        System.out.println();
        System.out.println();
        System.out.println();;
        orderDao.edit(orders);
    }


}
